<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
namespace App\Admin\Actions\Form;

use App\Service\User\PointAccountServices;
use Dcat\Admin\Admin;
use Dcat\Admin\Contracts\LazyRenderable;
use Dcat\Admin\Traits\LazyWidget;
use Dcat\Admin\Widgets\Form;

class UserAddPoint extends Form implements LazyRenderable
{
    use LazyWidget;

    /*
     * Handle the form request.
     *
     * @param array $input
     *
     * @return mixed
     */
    use LazyWidget;

    public function handle(array $input)
    {
        $id = $input['id'];
        $number = $input['number'];
        $admin = Admin::user();

        if ($number > 0) {
            $msg = sprintf('系统管理员:%s 拨调积分:%s', $admin->username, $number);
            PointAccountServices::make()->recharge($id, $number, $msg);
        } else {
            $msg = sprintf('系统管理员:%s 扣除积分:%s', $admin->username, abs($number));
            PointAccountServices::make()->consumption($id, abs($number), $msg);
        }

        return $this->response()
            ->success($msg)
            ->refresh();
    }

    /**
     * Build a form here.
     */
    public function form()
    {
        $this->number('number', '拨调积分')->required();
        //批量选择的行的值怎么传递看下面
        $this->hidden('id')->default($this->payload['id']);
    }

    /**
     * The data of the form.
     *
     * @return array
     */
    public function default()
    {
        //设置默认值
        return [
        ];
    }
}
